﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media;
using System.CodeDom;
using System.ComponentModel.Composition;

namespace NeuroSpeech.XamlExtensions
{
    [Export]
    public class BrushConverter : ColorConverter
    {

        #region public override bool  CanProcess(XamlCodeContext context)
        public override bool CanProcess(XamlCodeContext context)
        {
            Type type = context.Peek.MemberType;
            if (type != null && type.FullName == "System.Windows.Media.Brush")
                return true;
            return false;
        }
        #endregion

        #region protected override CodeExpression  ConvertValue(Type type, object val)
        protected override CodeExpression ConvertValue(Type type, object val)
        {
            CodeExpression ce = base.ConvertValue(type, val);
            CodeObjectCreateExpression cc = new CodeObjectCreateExpression { 
                CreateType = new CodeTypeReference("System.Windows.Media.SolidColorBrush")
            };
            cc.Parameters.Add(ce);
            return cc;
        }
        #endregion

    }
}
